<!-- 地址列表 -->
<template>
	<view class="address-wrap">
		<!-- #ifdef MP-WEIXIN -->
			<shopro-login-modal></shopro-login-modal>
		<!-- #endif -->
		<view class="address-list" v-for="address in addressList" :key="address.id" @tap="useAddress(address)">
			<view class="top u-flex">
				<text class="name">{{ address.name }}</text>
				<text class="phone">{{ address.mobile }}</text>
				<text class="tag" v-show="address.is_default==1">默认</text>
			</view>
			<view class="detail">
				{{ address.full_address }}{{address.address}}
			</view>
			<view class="u-reset-button set-btn"
				@tap.stop="edit(address.id)">编辑
			</view>
		</view>

		<view class="foot_box-wrap safe-area-inset-bottom">
			<view class="foot_box u-flex u-row-between safe-area-inset-bottom">
				<button class="u-reset-button add-btn u-m-20"
					@tap="goPage('/pages/prefile/address/edit')">+添加新的收货地址</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				addressList: [],
			};
		},
		computed: {},
		onLoad() {},
		onShow() {
			this.getAddressList();
		},
		methods: {
			
			edit(_id){
				this.goPage('/pages/prefile/address/edit', { id: _id });
			},
			// 选中
			useAddress(addressData) {
				uni.$emit('SELECT_ADDRESS', {
					addressId: addressData.id
				});
				uni.navigateBack({
				    delta: 1
				});
				// this.$Router.back();
			},
			getAddressList() {
				this.myHttp({
					url: '/api/memberaddress/page',
				}).then(res=>{
					this.addressList = res.data.list;
					!this.addressList.length && uni.$emit('SELECT_ADDRESS', {
						addressData: null
					});
				})
			}
		}
	};
</script>

<style lang="scss">
	.address-wrap{
		background: #f2f2f2;
		height: 100vh;
		@include flexCol;
		align-items: center;
	}
	.address-list {
		position: relative;
		margin-top: 20rpx;
		width: 700rpx;
		height: 155rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
		@include flexCol;
		justify-content: center;
		padding-left: 40rpx;
		.name {
			font-size: 30rpx;
			font-weight: 600;
		}

		.phone {
			font-size: 30rpx;
			margin: 0 20rpx;
		}

		.tag {
			background: rgba(233, 191, 113, 0.2);
			border-radius: 6rpx;
			padding: 0 16rpx;
			line-height: 38rpx;
			color: #a8700d;
			font-size: 22rpx;
		}

		.detail {
			margin-top: 25rpx;
			width: 543rpx;
			font-size: 26rpx;

			font-weight: 400;
			color: rgba(153, 153, 153, 1);
			line-height: 40rpx;
		}

		.set-btn {
			background: none;
			position: absolute;
			font-size: 26rpx;
			color: #CFA972;
			top: 50%;
			transform: translateY(-50%);
			right: 40rpx;
		}
	}

	// 底部按钮
	.foot_box-wrap {
		height: 140rpx;
		width: 100%;
	}

	.foot_box {
		padding: 10rpx 20rpx;
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		border-top: 1rpx solid rgba(#ccc, 0.2);

		.sync-wxaddress {
			flex: 1;
			line-height: 80rpx;
			background: rgba(255, 255, 255, 1);
			border-radius: 40rpx;
			box-shadow: 0 0 1rpx 6rpx rgba(#ccc, 0.2);
		}

		.add-btn {
			line-height: 80rpx;
			flex: 1;
			background: $themeColor;
			border-radius: 40rpx;
			color: rgba(#fff, 0.9);
		}
	}
</style>
